package com.tourManagement.service.impl;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.handler.BeanListHandler;
import com.tourManagement.entity.订单信息;
import com.tourManagement.service.订单管理Service;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

@Service
public class 订单管理ServiceImpl implements 订单管理Service {
    @Override
    public int addOrder(订单信息 data) throws SQLException {
        Date date = new Date();
        data.setOrderDate(date);
        String orderStatus = "0";
        data.setOrderStatus(orderStatus);
        Double orderTotalPrice = data.getPrice() * data.getOrderQuantity();
        data.setOrderTotalPrice(orderTotalPrice);
        return Db.use().insert(Entity.create("t_order").parseBean(data));
    }

    @Override
    public int deleteOrder(Integer orderId) throws SQLException {
        return Db.use().del(Entity.create("t_order").set("order_id",orderId));
    }

    @Override
    public int orderPayment(Integer orderId) throws SQLException {
        return Db.use().update(Entity.create().set("order_status",'1'),Entity.create("t_order").set("order_id",orderId));
    }

    @Override
    public List<订单信息> selectOneOrder(String userName) throws SQLException {
        return Db.use().query("select * from t_order where userName = ? order by order_date",new BeanListHandler<>(订单信息.class),userName);
    }

    @Override
    public List<订单信息> selectAllOrder() throws SQLException {
        return Db.use().query("select * from t_order order by order_date",new BeanListHandler<>(订单信息.class));
    }
}
